package com.xzj.admin.boot.service.impl;

import com.xzj.admin.base.domain.SysMenuInfo;
import com.xzj.admin.base.domain.SysRoleInfo;
import com.xzj.admin.base.domain.SysUserInfo;
import com.xzj.admin.boot.mapper.SystemMapper;
import com.xzj.admin.boot.service.SystemService;
import com.xzj.common.core.utils.TreeUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: xzj-admin
 * @ClassName: SystemServiceImpl
 * @description: 系统功能
 * @author: XiaZunJun
 * @create: 2024-06-24 14:30
 */
@Service
public class SystemServiceImpl implements SystemService {

    @Resource
    private SystemMapper systemMapper;


    @Override
    public SysUserInfo userInfoByName(String username) {
        SysUserInfo sysUserInfo = systemMapper.queryByName(username);
        if(null != sysUserInfo){
            List<SysRoleInfo> sysRoleInfos = systemMapper.queryRolesByUserId(sysUserInfo.getUserId());
            sysUserInfo.setRoles(sysRoleInfos);
        }
        return sysUserInfo;
    }

    @Override
    public SysUserInfo userInfoById(String userId) {
        SysUserInfo sysUserInfo = systemMapper.queryById(userId);
        if(null != sysUserInfo){
            List<SysRoleInfo> sysRoleInfos = systemMapper.queryRolesByUserId(sysUserInfo.getUserId());
            sysUserInfo.setRoles(sysRoleInfos);
        }
        return sysUserInfo;
    }

    @Override
    public List<SysMenuInfo> menuList(String userId) {
        List<SysMenuInfo> sysMenuInfos = systemMapper.queryMenuByUserId(userId);
        return TreeUtil.listToTree(sysMenuInfos);
    }

    @Override
    public List<String> perCodeList(String userId) {
        return systemMapper.queryPermissions(userId);
    }
}
